package com.codeavatar.hardwaretester.model;

import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.os.ParcelUuid;

import java.util.List;

/**
 * +----------------------------------------------------------------------
 * | @Author: codeavatar   @Year：2022
 * +----------------------------------------------------------------------
 * | @Email: codeavatar@aliyun.com
 * +----------------------------------------------------------------------
 **/
public class BluetoothCharacteristicModel {

    private String uuid;
    private boolean isRead;
    private boolean isWrite;
    private boolean isNotify;
    private boolean isIndicate;
    private List<BluetoothGattDescriptor> bluetoothGattDescriptorList;
    private BluetoothGattCharacteristic bluetoothGattCharacteristic;
    private int checkedIndex = -1;

    public BluetoothCharacteristicModel() {
    }

    public BluetoothCharacteristicModel(String uuid) {
        this.uuid = uuid;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public boolean isRead() {
        return isRead;
    }

    public void setRead(boolean read) {
        isRead = read;
    }

    public boolean isWrite() {
        return isWrite;
    }

    public void setWrite(boolean write) {
        isWrite = write;
    }

    public boolean isNotify() {
        return isNotify;
    }

    public void setNotify(boolean notify) {
        isNotify = notify;
    }

    public boolean isIndicate() {
        return isIndicate;
    }

    public void setIndicate(boolean indicate) {
        isIndicate = indicate;
    }

    public List<BluetoothGattDescriptor> getBluetoothGattDescriptorList() {
        return bluetoothGattDescriptorList;
    }

    public void setBluetoothGattDescriptorList(List<BluetoothGattDescriptor> bluetoothGattDescriptorList) {
        this.bluetoothGattDescriptorList = bluetoothGattDescriptorList;
        int tmpPermission = -1;
        for (BluetoothGattDescriptor descriptor : this.bluetoothGattDescriptorList){
            tmpPermission = descriptor.getPermissions();
            switch (tmpPermission){
                case BluetoothGattDescriptor.PERMISSION_READ:
                case BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED:
                case BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED_MITM:
                    this.setRead(true);
                    break;
                case BluetoothGattDescriptor.PERMISSION_WRITE:
                case BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED:
                case BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED_MITM:
                case BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED:
                case BluetoothGattDescriptor.PERMISSION_WRITE_SIGNED_MITM:
                    this.setWrite(true);
                    break;
            }
        }
    }

    public BluetoothGattCharacteristic getBluetoothGattCharacteristic() {
        return bluetoothGattCharacteristic;
    }

    public void setBluetoothGattCharacteristic(BluetoothGattCharacteristic bluetoothGattCharacteristic) {
        this.bluetoothGattCharacteristic = bluetoothGattCharacteristic;
    }

    public int getCheckedIndex() {
        return checkedIndex;
    }

    public void setCheckedIndex(int checkedIndex) {
        this.checkedIndex = checkedIndex;
    }
}
